package com.aliang.book_java1.java_util;

import com.aliang.book_java1.po.redis.MessagePublisher;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@Controller
@RequestMapping("/duty/dutyManagement")
public class Test1_controller {

    @RequestMapping(value = "/wwww", method = { RequestMethod.GET })
    public void getOutTopUserInfo(HttpServletResponse response) {
        System.out.println("---111");

    }

    @RequestMapping(value = "/doRedis", method = { RequestMethod.GET })
    public void doRedis(HttpServletResponse response) {
        messagePublisher.doRedis();

    }

    /**
     * 测试redis消息队列
     * @param response
     */
    @Resource
    MessagePublisher messagePublisher;

    @RequestMapping(value = "/testRedisMessageQueue", method = { RequestMethod.GET })
    public void testRedisMessageQueue(HttpServletResponse response) {
        // 执行一些操作
        String message = "Hello, Redis message queue!";
        for(int i=0;i<10;i++){
            messagePublisher.publishMessage(message+i);
        }

    }


    /**
     * 线下排班计划导入
     * @param file
     * @param response
     * @param request
     */
    @RequestMapping(value = "/uploadExcel", method = { RequestMethod.POST })
    //@ResponseBody
    public void uploadExcel(
            @RequestParam(value = "file", required = false) MultipartFile file,
            HttpServletResponse response, HttpServletRequest request) {

        try {
            String type = file.getOriginalFilename();
            System.out.println("--------type--------"+ type);
            ExportExcelUtil exportExcelUtil=new ExportExcelUtil();
            //String str=exportExcelUtil.importExcelEnterprise(file);//导入企业信息
            String str=exportExcelUtil.importExcelItem(file);//导入项目信息
            System.out.println("--返回结果-----"+str);
            //JsonResultUtils.writeSingleDataJson("操作成功", response);

        }catch (Exception e){
            e.printStackTrace();
            //JsonResultUtils.writeErrorMessageJson(601, "操作失败,请联系系统管理员", response);
        }

    }

}
